package rmioverlay.lib.users;

import rmioverlay.lib.users.role.Role;

public class User {
	
	private boolean logged;
	private String pass;
	private String login;
	private Role role;
	
	/**
	 * Instantiates a new User
	 * @param pLogin the chosen login
	 * @param pPass the chosen pass (no hash)
	 * @param pRole the chosen User's role
	 */
	public User(String pLogin, String pPass, Role pRole){
		this.logged = false;
		this.login = pLogin;
		this.pass = pPass;
		this.role = pRole;
	}
	
	public User(String pLogin, String pPass) {
		this(pLogin, pPass, null);
	}
	
	/**
	 * Logs the user in
	 * @param pPass the password to check
	 * @return whether the login passed or not 
	 */
	public boolean login(String pPass){
		if(this.pass.equals(pPass)){
			this.logged=true;
		}
		return this.logged;
	}
	
	/**
	 * Logs the user out
	 */
	public void logout(){
		this.logged = false;
	}
	
	/**
	 * Gets the user's login
	 * @return the user's login
	 */
	public String getLogin() { return this.login; }
	
	/**
	 * Gets the user's role
	 * @return the user's role
	 */
	public Role getRole() { return this.role; }
	
	/**
	 * Check the equality of two Users
	 * @return whether the two Users are equals or not
	 */
	public boolean equals(Object o){
		if (o instanceof User) {
			User u = (User)o;
			if (this.login.equals(u.login) && this.login.equals(u.pass))
				return true;
		}
		return false;
	}
}
